package com.wyix.repository;

import com.wyix.domain.BorrowRecord;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * @author wangdx
 * @since 2025/8/26
 */
@Repository
public interface BorrowRecordRepository extends JpaRepository<BorrowRecord, Long> {
    // 查询用户的所有借阅记录
    List<BorrowRecord> findByUserId(Long userId);

    // 查询用户未归还的借阅记录
    @Query("SELECT br FROM BorrowRecord br WHERE br.userId = :userId AND br.status = 0")
    List<BorrowRecord> findUnreturnedRecordsByUserId(@Param("userId") Long userId);

    // 查询图书的借阅记录
    List<BorrowRecord> findByBookId(Long bookId);
}
